# ============================================================== # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Desktop Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description: Script to reset Microsoft Edge (clears 'Cache','Cache2\entries','Cookies','History','Top Sites','Visited Links','Web Data','Media History','Cookies-Journal') # for a specific user # Parameters: # Remarks: # The script has to be deployed as User Configuration # The Script will kill the Browser, if running # Configuration Type - User # ============================================================== Function Remove-CacheFiles { param([Parameter(Mandatory=$true)][string]$path) BEGIN { $originalVerbosePreference = $VerbosePreference $VerbosePreference = 'Continue' } PROCESS { if((Test-Path $path)) { if([System.IO.Directory]::Exists($path)) { try { if($path[-1] -eq '\') { [int]$pathSubString = $path.ToCharArray().Count - 1 $sanitizedPath = $path.SubString(0, $pathSubString) Remove-Item -Path "$sanitizedPath\*" -Recurse -Force -ErrorAction SilentlyContinue -Verbose } else { Remove-Item -Path "$path\*" -Recurse -Force -ErrorAction SilentlyContinue -Verbose } } catch { } } else { try { Remove-Item -Path $path -Force -ErrorAction SilentlyContinue -Verbose } catch { } } } } END { $VerbosePreference = $originalVerbosePreference } } Function Clear-EdgeCache { param([string]$user=$env:USERNAME) Stop-Process -Name MicrosoftEdge -Force if((Test-Path "C:\Users$user\AppData\Local\Microsoft\Edge\User Data\Default")) { $EdgeAppData = "C:\Users$user\AppData\Local\Microsoft\Edge\User Data\Default" $possibleCachePaths = @('Cache','Cache2\entries','Cookies','History','Top Sites','Visited Links','Web Data','Media History','Cookies-Journal') ForEach($cachePath in $possibleCachePaths) { Remove-CacheFiles "$EdgeAppData$cachePath" } } } Clear-EdgeCache